<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri='http://java.sun.com/portlet' prefix='portlet'%>
<%@ page import="javax.portlet.*"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.com.chinasoa.course.subscribe.model.*"%>
<%@ page import="cn.com.chinasoa.course.subscribe.util.*"%>
<%@ page import="com.x4ee.soa.portal.framework.tools.*"%>
<%@ page import="javax.persistence.*"%>
<%String contextPath = request.getContextPath();%>
<portlet:defineObjects />
<link href='<%=contextPath%><%=ConfigUtils.getResourceBasePath(renderRequest)%>/css/portlet.css' rel='stylesheet' type='text/css'/>
<script language="JavaScript"  type="text/javascript" src="<%=contextPath%><%=ConfigUtils.getResourceBasePath(renderRequest)%>/javascript/prototype.js"></script>
<script language="JavaScript"  type="text/javascript" src="<%=contextPath%><%=ConfigUtils.getResourceBasePath(renderRequest)%>/javascript/calendar.js"></script>

<div id="calendarPanel" style="position: absolute;visibility: hidden;z-index: 9999;background-color: #FFFFFF;border: 1px solid #CCCCCC;width:175px;font-size:12px;"></div>
<form method='post' action='<portlet:actionURL><portlet:param name="frameworkUri" value="arrangedCourseOperateAction"/><portlet:param name="cmd" value="edit"/></portlet:actionURL>'>
<table>
	<tr>
		<td valign="top">
			<table>
				<tr><td><a href='<portlet:renderURL portletMode="EDIT"><portlet:param name="frameworkUri" value="EditIndex"/></portlet:renderURL>'>[发布课程]</a></td></tr>
				<tr><td><a href='<portlet:renderURL portletMode="HELP"><portlet:param name="frameworkUri" value="TrainingSubjectCreate"/></portlet:renderURL>'>[授课科目]</a></td></tr>				
				<tr><td><a href='<portlet:renderURL portletMode="HELP"><portlet:param name="frameworkUri" value="TrainingAddressCreate"/></portlet:renderURL>'>[授课地点]</a></td></tr>
				<tr><td><a href='<portlet:renderURL portletMode="HELP"><portlet:param name="frameworkUri" value="PrivilegeStrategyCreate"/></portlet:renderURL>'>[优惠策略]</a></td></tr>				
				<tr><td><a href='<portlet:renderURL portletMode="EDIT"><portlet:param name="frameworkUri" value="SubscribeOrderView"/></portlet:renderURL>'>[处理订单]</a></td></tr>				
			</table>
		</td>
		<td>
			<table>
			<%List<TrainingSubject> tsList = ModelEntityHelper.listTrainingSubject();
			List<PrivilegeStrategy> psList = ModelEntityHelper.listPrivilegeStrategy();
			long arrangedCourseId = DataTypeUtil.parseLong(renderRequest.getParameter("arrangedCourseId"));
					EntityManager em = EntityManagerHelper.getEntityManager();
					if(arrangedCourseId>=0){
						ArrangedCourse tac = em.find(ArrangedCourse.class,arrangedCourseId);
						if(tac!=null){%><input name="arrangedCourseId" type="hidden" value="<%=arrangedCourseId%>"/>	
<tr><th colspan="2" align="left" style="font-size: 13">发布近期课程</th></tr>
<tr><td colspan="2"><table><tr><td align="left">课程标题:</td><td><input name="courseTitle" type="text" size="20" class="textfield" value="<%=tac.getCourseTitle()%>"/></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">课程介绍:</td><td><input name="courseDescription" type="text" size="20" class="textfield" value="<%=tac.getCourseDescription()%>"/></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">授课科目:</td><td><select name="trainingSubject">
					<%for(Iterator<TrainingSubject> tsIt = tsList.iterator();tsIt.hasNext();){
						TrainingSubject ts = tsIt.next();%><option value="<%=ts.getId()%>" title="<%=ts.getSummary()%>" <%if(tac.getTrainingSubject().getId()==ts.getId()){%>selected="selected"<%}%>><%=ts.getCode()%></option>
					<%}%></select></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">开始日期:</td><td><input name="startDate" value="<%=DataTypeUtil.renderCalender(tac.getStartDate())%>" type="text" size="8" class="textfield" maxlength="10" size="10" readonly="readonly" onclick="new Calendar().show(this);"/></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">结束日期:</td><td><input name="endDate" value="<%=DataTypeUtil.renderCalender(tac.getEndDate())%>" type="text" size="8" class="textfield" maxlength="10" size="10" readonly="readonly" onclick="new Calendar().show(this);"/></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">培训地点:</td><td><select name="trainingAddress"><%List<TrainingAddress> taList = ModelEntityHelper.listTrainingAddress();for(Iterator<TrainingAddress> taIt = taList.iterator();taIt.hasNext();){TrainingAddress ta = taIt.next();%><option value="<%=ta.getId()%>" title="<%=ta.getAddress()%>" <%if(tac.getTrainingAddress().getId()==ta.getId()){%>selected="selected"<%}%>><%=ta.getCity()%></option><%}%></select></td></tr></table></td></tr>
<tr><td colspan="2"><table><tr><td align="left">优惠措施:</td><td><table>
					<%List<Long> tpsIdList = new ArrayList<Long>();
					for(Iterator<PrivilegeStrategy> tpsIt = tac.getPrivilegeStrategys().iterator();tpsIt.hasNext();){
						tpsIdList.add(tpsIt.next().getId());
					}
					for(Iterator<PrivilegeStrategy> psIt = psList.iterator();psIt.hasNext();){
							PrivilegeStrategy ps = psIt.next();%><tr><td><input type="Checkbox" name="privilegeStrategy_<%=ps.getId()%>" value="<%=ps.getId()%>" <%if(tpsIdList.contains(ps.getId())){%>checked="checked"<%}%>><%=ps.getDescription()%></input></td></tr>
						<%}%></table></td></tr></table></td></tr>		
<tr><td colspan="2"><table><tr><td align="left"><input type="image" src="<%=contextPath%><%=ConfigUtils.getResourceBasePath(renderRequest)%>/image/pub.jpg" name="Submit" value="发布"></td></tr></table><td></tr>
					<%}}EntityManagerHelper.closeEntityManager();%>
			</table>
			
		</td>
		<td valign="top">
			<table border="1">
			<tr><td>开始时间</td><td>培训地点</td><td>培训编号</td><td>结束时间</td><td>课程价格</td></tr>
			<%EntityManager tem = EntityManagerHelper.getEntityManager();
			Query q = tem.createQuery("select ac from ArrangedCourse ac");
			List acList = q.getResultList();
			for(Iterator acIt = acList.iterator();acIt.hasNext();){
				Object acObj = acIt.next();
				if((acObj!=null)&&(acObj instanceof ArrangedCourse)){
					ArrangedCourse ac = (ArrangedCourse)acObj;%>
	<tr><td><strong><%=DataTypeUtil.renderCalender(ac.getStartDate())%></strong></td>
	<td align="center"><a href="#" title="<%=ac.getTrainingAddress().getAddress()%>"><strong><%=ac.getTrainingAddress().getCity()%></strong></a></td>
	<td><a href="#" title="<%=ac.getCourseTitle()%>"><strong><%=ac.getTrainingSubject().getCode()%></strong></a></td>	
	<td><strong><%=DataTypeUtil.renderCalender(ac.getEndDate())%></strong></td>
	  <%String psListValue = "";
		List<PrivilegeStrategy> tpsList = ac.getPrivilegeStrategys();
		for(Iterator<PrivilegeStrategy> tpsIt = tpsList.iterator();tpsIt.hasNext();){
			PrivilegeStrategy tps = tpsIt.next();
			psListValue+=(tps.getDescription()+"\n");
		}%>
		<td align="center"><a href="#" title="<%=psListValue%>"><strong><%=ac.getTrainingSubject().getPrice()%></strong></a></td>
		<td><a href="<portlet:renderURL><portlet:param name="frameworkUri" value="ArrangedCourseEdit"/><portlet:param name="arrangedCourseId" value="<%=ac.getId()+""%>"/></portlet:renderURL>">[编辑]</a>
				<a href="<portlet:actionURL><portlet:param name="frameworkUri" value="arrangedCourseOperateAction"/><portlet:param name="arrangedCourseId" value="<%=ac.getId()+""%>"/><portlet:param name="cmd" value="delete"/></portlet:actionURL>">[删除]</a></td>
		</tr><%}}EntityManagerHelper.closeEntityManager();%></table>
		</td>
	</tr>
</table>
</form>
